package com.ogilvy.cms.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ogilvy.cms.bean.CmsLog;
import com.ogilvy.cms.dao.CmsLogDao;
import com.ogilvy.cms.service.CmsLogService;
import com.ogilvy.frame.service.BaseServiceImpl;
import com.ogilvy.frame.util.ApplicationResources;
import com.thtf.core.common.util.Configuration;

@Service
public class CmsLogServiceImpl extends BaseServiceImpl implements CmsLogService {
	@Autowired
	protected CmsLogDao cmsLogDao;
	final static boolean flag = new Boolean(ApplicationResources.getText("log.flag")).booleanValue();
	public CmsLog add(CmsLog cmsLog) {
		/*读取配置文件中的标记 为true时，保存；否则不保存*/
		Configuration config= Configuration.getInstance("/ogilvyCms.properties");
		CmsLog cmslog = null;
		//日志开关
		if(flag)
		{
			cmslog = cmsLogDao.save(cmsLog);
		}
		return cmslog;
	}

	public boolean del(Integer cmlId) {
		cmsLogDao.deleteById(cmlId);
		return true;
	}

	public boolean modify(CmsLog cmsLog) {
		cmsLogDao.update(cmsLog);
		return true;		
	}

	public List<CmsLog> query(CmsLog cmsLog) {
		if(isEmpty(cmsLog.getCmlFunction())){
			return cmsLogDao.findAll();
		}
		return cmsLogDao.findByProperty("cmlFunction", cmsLog.getCmlFunction());
	}
	 /**根据筛选条件查询相关信息*/
	public List<CmsLog> queryByScreen(Map<String, String> screenMap) {
		return cmsLogDao.getListByScreen(screenMap);
	}

}
